

function change_confirm() {
    if (getValueId('confirm_register', 'checked')) {
        $('#submit').removeClass('register-button-submit-disabled');
        $('#submit').addClass('register-button-submit');
        $('#submit').removeAttr('disabled');
    }
    else {
        $('#submit').removeClass('register-button-submit');
        $('#submit').addClass('register-button-submit-disabled');
        $('#submit').attr('disabled', 'disabled');
    }
}

var userImage = "";
$().ready(function () {
    //	$().ajaxComplete(function(r,s){
    //		$("#loading-layer").fadeOut("slow");
    //	});	
    $(".text3").datepicker({ dateFormat: 'mm/dd/yy' });
    apply_json('registerCateggory', categories_json, 'CategoriesInRegister');
    ajax_request('GetAllDealType', '', 'registerDealType', "DealTypeInRegister");
    ajax_request('GetRegionByParent', 'parentId:0', 'registerRegion', "RegionInRegister");
    //    $("#registerRegion").change(function () {
    //        ajax_request('GetRegionByParent', 'parentId:' + $("#registerRegion").val(), 'registerDistrict', "RegionInRegister");
    //    });
    $("#registerDealType").change(function () {
        if ($("#registerDealType option:selected").text() == "Giảm giá") {
            $("#dPrive").css('display', 'block')
        }
        else {
            $("#dPrive").css('display', 'none')
        }
    });

    (function ($) {
        $('#wysiwyg').wysiwyg({
            controls: {
                strikeThrough: { visible: true },
                underline: { visible: true },

                separator00: { visible: true },

                justifyLeft: { visible: true },
                justifyCenter: { visible: true },
                justifyRight: { visible: true },
                justifyFull: { visible: true },

                separator01: { visible: true },

                indent: { visible: true },
                outdent: { visible: true },

                separator02: { visible: true },

                subscript: { visible: true },
                superscript: { visible: true },

                separator03: { visible: true },

                undo: { visible: true },
                redo: { visible: true },

                separator04: { visible: true },

                insertOrderedList: { visible: true },
                insertUnorderedList: { visible: true },
                insertHorizontalRule: { visible: true },

                h4mozilla: { visible: true && $.browser.mozilla, className: 'h4', command: 'heading', arguments: ['h4'], tags: ['h4'], tooltip: "Header 4" },
                h5mozilla: { visible: true && $.browser.mozilla, className: 'h5', command: 'heading', arguments: ['h5'], tags: ['h5'], tooltip: "Header 5" },
                h6mozilla: { visible: true && $.browser.mozilla, className: 'h6', command: 'heading', arguments: ['h6'], tags: ['h6'], tooltip: "Header 6" },

                h4: { visible: true && !($.browser.mozilla), className: 'h4', command: 'formatBlock', arguments: ['<H4>'], tags: ['h4'], tooltip: "Header 4" },
                h5: { visible: true && !($.browser.mozilla), className: 'h5', command: 'formatBlock', arguments: ['<H5>'], tags: ['h5'], tooltip: "Header 5" },
                h6: { visible: true && !($.browser.mozilla), className: 'h6', command: 'formatBlock', arguments: ['<H6>'], tags: ['h6'], tooltip: "Header 6" },

                separator07: { visible: true },

                cut: { visible: true },
                copy: { visible: true },
                paste: { visible: true }
            }
        });
    })(jQuery);
    $(function () {
        //Function to upload file.
        new AjaxUpload('#uploadFile', {
            action: '../services/FileUploadHandler.ashx',
            name: 'upload',
            onComplete: function (file, response) {
                deleteFile(userImage);
                userImage = response;
                $("#hdfImage").val(response);
                $("#ctImages").val(response.substring(response.lastIndexOf("/") + 1, response.length));
            },
            onSubmit: function (file, ext) {
                if (!(ext && /^(txt|doc|docx|xls|pdf|jpg|png|gif)$/i.test(ext))) {
                    alert('Invalid File Format.');
                    return false;
                }
            }
        });
    });
    function deleteFile() {
        if (userImage != "")
            $.ajax({ url: '../services/FileUploadHandler.ashx?del=' + userImage, success: function () {
                alert("Ảnh hiển thị đã được cập nhật!");
            }
            });
    }
    $("#Register").validate({
        errorElement: "em",
        success: function (label) {
            label.text("").addClass("success");
        },
        rules: {
            title: {
                minlength: 4,
                maxlength: 255
            },
            description: {
                minlength: 10,
                maxlength: 250
            },
            registerCateggory: {
                required: true,
                number: true
            },
            registerDealType: {
                required: true,
                number: true
            },
            price: {
            //required: true,
            //number: true
        },
        promotion: {
        //required: true,
        //number: true
    },
    pprice: {
    //required: true,
    //number: true
}
},
messages: {
    title: {
        minlength: "Tiêu đề tối thiểu 4 ký tự",
        maxlength: "Tiêu đề tối đa 225 ký tự"
    },
    description: {
        minlength: "Mô tả tối thiểu 10 ký tự",
        maxlength: "Mô tả tối đa 250 ký tự"
    },
    price: {
    //required: "&nbsp;",
    //number: "&nbsp;"
},
promotion: {
//required: "&nbsp;",
//number: "&nbsp;"
},
pprice: {
//required: "&nbsp;",
//number: "&nbsp;"
},
captcha_register: {
    required: "Bạn chưa nhập mã bảo mật",
    remote: "Mã bảo mật chưa đúng"
}
}

        , submitHandler: function (form) {
            //            $.ajax({
            //                url: '../services/Handler.ashx',
            //                type: 'POST',
            //                data: 'action='post_deals'&data=' + email + '

            //                success: function (result) {
            //                    $('#response').remove();
            //                    $('#container').append('<p id="response">' + result + '</p>');
            //                    $('#loadining').fadeOut(500, function () {
            //                        $(this).remove();
            //                    });
            //                }
            //            });
            $('#message').html("<div class=\"notice_warning\"><img src=\"/images/warning.png\"><h6>Thông báo !</h6><p>Đang xử lý .........</p></div>");
            $('html, body').animate({ scrollTop: 0 }, 'slow');
            if ($("#action") && $("#action").val() == "update") {
                $.post("/services/Handler.ashx", { action: 'update_deals', data: +$("#registerCateggory").val() + ";_*-(-18*****" + $("#registerRegion").val() + ";_*-(-18***** 1 ;_*-(-18*****" + $("#registerDealType").val() + ";_*-(-18*****;_*-(-18*****/" + $("#hdfImage").val() + ";_*-(-18***** " + $("#title").val() + ";_*-(-18***** " + $("#description").val() + ";_*-(-18***** " + $("#wysiwyg").val() + ";_*-(-18***** " + $("#title").val() + ";_*-(-18***** " + $("#title").val() + ";_*-(-18***** 0;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****;_*-(-18***** 0;_*-(-18***** 0;_*-(-18***** true;_*-(-18***** true;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****" + getCurrentdate() + ";_*-(-18***** 1;_*-(-18***** 1;_*-(-18***** " + $("#price").val() + ";_*-(-18***** " + $("#pprice").val() + ";_*-(-18***** " + $("#promotion").val() + ";_*-(-18***** true;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****;_*-(-18***** " + $("#startDate").val() + ";_*-(-18***** " + $("#endDate").val() + ";_*-(-18*****" + getCurrentdate() + ";_*-(-18*****admin;_*-(-18*****;_*-(-18***** 1;_*-(-18***** " + id },
                function (response) {
                    $('#message').html(response);
                });
            }
            else {
                $.post("../services/Handler.ashx", { action: 'post_deals', data: +$("#registerCateggory").val() + ";_*-(-18*****" + $("#registerRegion").val() + ";_*-(-18***** 1 ;_*-(-18*****" + $("#registerDealType").val() + ";_*-(-18*****;_*-(-18*****/" + $("#hdfImage").val() + ";_*-(-18***** " + $("#title").val() + ";_*-(-18***** " + $("#description").val() + ";_*-(-18***** " + $("#wysiwyg").val() + ";_*-(-18***** " + $("#title").val() + ";_*-(-18***** " + $("#title").val() + ";_*-(-18***** 0;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****;_*-(-18***** 0;_*-(-18***** 0;_*-(-18***** true;_*-(-18***** true;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****" + getCurrentdate() + ";_*-(-18***** 1;_*-(-18***** 1;_*-(-18***** " + $("#price").val() + ";_*-(-18***** " + $("#pprice").val() + ";_*-(-18***** " + $("#promotion").val() + ";_*-(-18***** true;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****;_*-(-18***** " + $("#startDate").val() + ";_*-(-18***** " + $("#endDate").val() + ";_*-(-18*****" + getCurrentdate() + ";_*-(-18*****admin;_*-(-18*****;_*-(-18***** 1" },
            function (response) {
                $('#message').html(response);
            });
            }
            //            handler_submit("post_deals", $("#registerCateggory").val() + ";_*-(-18*****" + $("#registerRegion").val() + ";_*-(-18***** 1 ;_*-(-18*****" + $("#registerDealType").val() + ";_*-(-18*****;_*-(-18*****/" + $("#hdfImage").val() + ";_*-(-18***** " + encodeURIComponent($("#title").val()) + ";_*-(-18***** " + encodeURIComponent($("#description").val()) + ";_*-(-18***** " + encodeURIComponent($("#wysiwyg").val()) + ";_*-(-18***** " + encodeURIComponent($("#title").val()) + ";_*-(-18***** " + encodeURIComponent($("#title").val()) + ";_*-(-18***** 0;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****;_*-(-18***** 0;_*-(-18***** 0;_*-(-18***** true;_*-(-18***** true;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****" + getCurrentdate() + ";_*-(-18***** 1;_*-(-18***** 1;_*-(-18***** " + $("#price").val() + ";_*-(-18***** " + $("#pprice").val() + ";_*-(-18***** " + $("#promotion").val() + ";_*-(-18***** true;_*-(-18*****" + getCurrentdate() + ";_*-(-18*****;_*-(-18***** " + $("#startDate").val() + ";_*-(-18***** " + $("#endDate").val() + ";_*-(-18*****" + getCurrentdate() + ";_*-(-18*****admin;_*-(-18*****;_*-(-18***** 1", "message");
            //$('html, body').animate({ scrollTop: 0 }, 'slow');
            return false;
        }
});

});